﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace com.zhongjh.Library.Database
{
    /// <summary>
    /// 数据库连接串实体类
    /// </summary>
    public static class DbCSEntity
    {
        /// <summary>
        /// Sql连接串
        /// </summary>
        public static string strSql = @"Data Source={DbServerNameOrPath};Initial Catalog= {DbName};UID={DbUser};Password={DbPassword};";//OK
        /// <summary>
        /// MySql连接串
        /// </summary>
        public static string strMySql = @"Data Source={DbServerNameOrPath};Initial Catalog={DbName};UID={DbUser};Password={DbPassword}";//OK
        /// <summary>
        /// Oracle连接串
        /// </summary>
        public static string strOracle = @"Data Source={DbServerNameOrPath};Initial Catalog={DbName};UID={DbUser};Password={DbPassword}";        
        /// <summary>
        /// OleDbAccess连接串
        /// </summary>
        public static string strOleDbAccess = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={DbServerNameOrPath};User Id={DBUser};Password={DbPassword};";//OK
       
        /// <summary>
        /// 取连接串
        /// </summary>
        /// <param name="p_EDbDrive">数据库驱动</param>
        /// <param name="p_EDbType">数据库类型</param>
        /// <param name="p_connectionString">传入连接串</param>
        /// <returns>返回处理后的连接串</returns>
        public static string GetConnectionString(EDbType p_EDbType, string p_connectionString)
        {
            string result = string.Empty;

            EDbType dbType = (EDbType)p_EDbType;

            if (p_connectionString == string.Empty)
            {
                switch (dbType)
                {
                    case EDbType.Access:
                        result = DbCSEntity.strOleDbAccess;
                        break;
                    case EDbType.Sql:
                        result = DbCSEntity.strSql;
                        break;
                    case EDbType.MySql:
                        result = DbCSEntity.strMySql;
                        break;
                    case EDbType.Oracle:
                        result = DbCSEntity.strOracle;
                        break;
                }
            }
            else
            {
                result = p_connectionString;
            }

            return result;
        }
    }
}
